package cn.kgc.vue.commons;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;

/**
 * @author 课工场
 * @date 2024/6/28
 * @description 统一响应格式
 */
@Data
@ApiModel("ResponseResult")
public class ResponseResult {

    @ApiModelProperty(value = "状态码",required = true,example = "0")
    private Integer code;
    @ApiModelProperty(value = "提示信息",required = true,example = "操作成功")
    private String message;
    @ApiModelProperty(value = "返回数据",required = true,example = "{pageData:{},total:100}")
    private HashMap<String, Object> data = new HashMap<>();


    private ResponseResult(){}

    // 成功
    public static ResponseResult success() {
        ResponseResult responseResult = new ResponseResult();
        responseResult.code = ResponseStatus.SUCCESS.getCode();
        responseResult.message = ResponseStatus.SUCCESS.getMessage();
        return responseResult;
    }

    // 失败
    public static ResponseResult fail() {
        ResponseResult responseResult = new ResponseResult();
        responseResult.code = ResponseStatus.FAIL.getCode();
        responseResult.message = ResponseStatus.FAIL.getMessage();
        return responseResult;
    }


    // 异常
    public static ResponseResult error() {
        ResponseResult responseResult = new ResponseResult();
        responseResult.code = ResponseStatus.ERROR.getCode();
        responseResult.message = ResponseStatus.ERROR.getMessage();
        return responseResult;
    }


    // message
    public ResponseResult  message(String message){
        this.message = message;
        return this;
    }

    // code
    public ResponseResult  code(Integer code){
        this.code=code;
        return this;
    }


    // data
    public ResponseResult  data(String key,Object value){
        this.data.put(key,value);
        return this;
    }



}
